package com.java.web;

import com.java.dao.userDao;
import com.java.dao.userDaoImpl;
import com.java.doMain.user;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author xyd
 * @Date 2021/12/22 17:43
 * @Version 1.0
 */
public class registerServlet extends HttpServlet {

    private userDao userDao = new userDaoImpl();

    protected void doGet(HttpServletRequest re, HttpServletResponse resp) throws ServletException, IOException {

        String username = re.getParameter("username");
        String password = re.getParameter("password");
        String gender = re.getParameter("gender");
        String telephone = re.getParameter("telephone");
        String introduce = re.getParameter("introduce");

        user user = userDao.selectByUsername(username);
        if (user==null){
            userDao.register(username, password, gender, telephone, introduce);
            re.getRequestDispatcher(re.getContextPath() + "/client/login.jsp").forward(re,resp);
        }else {
            re.setAttribute("err","<h4><font color='red'>该账号已被注册!</font></h4>");
            re.getRequestDispatcher(re.getContextPath() + "/client/register.jsp").forward(re,resp);
            return ;
        }
    }
}
